package com.wyth.lottery.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wyth.lottery.R;
import com.wyth.lottery.bean.SSQSelectBean;
import com.wyth.lottery.utils.MyApplication;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by phh on 2017/11/2.
 */

public class ShoppingNumberAdapter extends RecyclerView.Adapter {

    private List<SSQSelectBean> mList;

    public ShoppingNumberAdapter(List<SSQSelectBean> list) {
        mList = list;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.adapter_number_shopping, null);

        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;
        SSQSelectBean ssqSelectBean = mList.get(position);

        boolean selectBoolean = ssqSelectBean.selectBoolean;
        boolean isBoolean = ssqSelectBean.isBoolean;

        if (selectBoolean) {
            if (selectBoolean ==true&&isBoolean==true){
                viewHolder.mTextView.setBackgroundResource(R.mipmap.img_red_backgroup);
                viewHolder.mTextView.setText(String.valueOf(ssqSelectBean.getText()));
            }else if (selectBoolean==true&&isBoolean==false){
                viewHolder.mTextView.setBackgroundResource(R.mipmap.img_yellow_backgroup);
                viewHolder.mTextView.setText(String.valueOf(ssqSelectBean.getText()));
            }
        } else {
            viewHolder.mTextView.setBackgroundResource(R.mipmap.img_blue_backgroup);
            viewHolder.mTextView.setText(String.valueOf(ssqSelectBean.getText()));
        }


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTextView;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTextView = (TextView) itemView.findViewById(R.id.text);
        }
    }
}